/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */

package com.fuyao.cloud.asset.inventory.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.asset.inventory.dto.InventoryTaskAssetSearchDTO;
import com.fuyao.cloud.common.biz.dto.PageQuery;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.data.mybatis.SpliceQueryWrapper;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.asset.inventory.entity.InventoryTaskAsset;
import com.fuyao.cloud.asset.inventory.service.InventoryTaskAssetService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Book;
import java.util.List;

/**
 * 盘点任务清单表
 *
 * @author lyhills
 * @date 2023-09-11 12:01:55
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/inventorytaskasset")
@Api(value = "inventorytaskasset", tags = "盘点任务清单表管理")
public class InventoryTaskAssetController {

    private final InventoryTaskAssetService inventoryTaskAssetService;

    /**
     * 分页查询
     *
     * @param page               分页对象
     * @param inventoryTaskAsset 盘点任务清单表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/page")
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_view')")
    public R page(Page page, InventoryTaskAsset inventoryTaskAsset) {
        return R.ok(inventoryTaskAssetService.page(page, Wrappers.query(inventoryTaskAsset)));
    }

    /**
     * 分页查询
     *
     * @param pageQuery 分页对象
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/getInventoryTaskAssetPage")
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_view')")
    public R getInventoryTaskAssetPage(PageQuery<InventoryTaskAssetSearchDTO> pageQuery) {
        return R.ok(inventoryTaskAssetService.getInventoryTaskAssetPage(pageQuery.getPage(), SpliceQueryWrapper.spliceSearchCondition(pageQuery.getExample()), pageQuery.getExample()));
    }


    /**
     * 通过id查询盘点任务清单表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_view')")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(inventoryTaskAssetService.getById(id));
    }

    /**
     * 新增盘点任务清单表
     *
     * @param inventoryTaskAsset 盘点任务清单表
     * @return R
     */
    @ApiOperation(value = "新增盘点任务清单表", notes = "新增盘点任务清单表")
    @SysLog("新增盘点任务清单表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_add')")
    public R save(@RequestBody InventoryTaskAsset inventoryTaskAsset) {
        boolean save = inventoryTaskAssetService.save(inventoryTaskAsset);
        return R.ok(inventoryTaskAsset);
    }

    /**
     * 修改盘点任务清单表
     *
     * @param inventoryTaskAsset 盘点任务清单表
     * @return R
     */
    @ApiOperation(value = "修改盘点任务清单表", notes = "修改盘点任务清单表")
    @SysLog("修改盘点任务清单表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_edit')")
    public R updateById(@RequestBody InventoryTaskAsset inventoryTaskAsset) {
        return R.ok(inventoryTaskAssetService.updateById(inventoryTaskAsset));
    }

    /**
     * 通过id删除盘点任务清单表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除盘点任务清单表", notes = "通过id删除盘点任务清单表")
    @SysLog("通过id删除盘点任务清单表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_del')")
    public R removeById(@PathVariable Long id) {
        return R.ok(inventoryTaskAssetService.removeById(id));
    }


    /**
     * 导出excel 表格
     *
     * @param inventoryTaskAsset 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_export')")
    public List<InventoryTaskAsset> export(InventoryTaskAsset inventoryTaskAsset) {
        return inventoryTaskAssetService.list(Wrappers.query(inventoryTaskAsset));
    }

    /**
     * 创建方法
     *
     * @return
     */
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_add')")
    @GetMapping(value = "/create")
    public R create() {
        return R.ok(inventoryTaskAssetService.create());
    }

    /**
     * 批量删除方法
     *
     * @param ids
     * @return R
     */
    @ApiOperation(value = "批量删除", notes = "批量删除通知公告")
    @SysLog("批量删除盘点任务清单表")
    @DeleteMapping("/batchDelete")
    @PreAuthorize("@pms.hasPermission('inventory_inventorytask_del')")
    public R batchDelete(@RequestBody List<Long> ids) {
        return R.ok(inventoryTaskAssetService.removeByIds(ids));
    }
}
